package com.zrrd.bufferedStream;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
 * @author WanJl
 * @version 1.0
 * @title BufferedInputStreamDemo01
 * @description 字节缓冲输入流
 * @create 2024/5/25
 */
public class BufferedInputStreamDemo01 {
    public static void main(String[] args) {
        FileInputStream fis = null;
        BufferedInputStream bis = null;
        try {
            //创建字节输入流对象，以文件路径为参数，操作的是文件
            fis = new FileInputStream("E:/users/abc.txt");
            //创建字节缓冲输入流对象，以字节输入流对象为参数，操作的是字节输入流
            bis = new BufferedInputStream(fis);

            //输入数据
            byte[] buffer = new byte[1024];
            int len;
            //这是货轮，货轮上面装集装箱，集装箱里面装货物
            while ((len=bis.read(buffer))!=-1){
                System.out.println(new String(buffer,0,len));
            }
            //这是货车，货车上面装货物
//            while ((len=bis.read())!=-1){
//
//            }

        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            try {
                bis.close();
                fis.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
